package name.fowler.refactoring.simplestore.services;

import name.fowler.refactoring.simplestore.domain.Customer;

import java.util.LinkedList;
import java.util.List;

/**
 * Date: 01.10.13
 * Time: 9:37
 */

public class ReportBuilder {
    private Formatter formatter;
    private Report report;

    public ReportBuilder(Formatter formatter, Report report) {
        this.formatter = formatter;
        this.report = report;
    }

    public String getReport(List<Customer> customers) {
        String result = report.getReportTitle();
        LinkedList<String> list = new LinkedList<>();
        for (Customer customer : customers) {
            if (report.isPrintDebitor(customer)) {
                String str = report.getCustomerHeader(customer) + report.getCustomerFooter(customer, formatter);
                list.add(str);
            }
        }
        result += formatter.printList(list) + report.getReportFooter() + report.getTotal(customers) + "\n";
        return result;
    }

}
